package com.app.util.lang;

import java.math.BigInteger;

public class MathUtil {

	public static final Float floatRound(Float f, int decimalCount) {
		if (null == f)
			return f;
		f = floatRound(f.floatValue(), decimalCount); 
		return f;
	}

	public static final float floatRound(float f, int decimalCount) {
		if (decimalCount < 0) {
			throw new IllegalArgumentException("Decimal count can not < 0.");
		}
		float n = (float) (f * Math.pow(10, decimalCount));
		n = Math.round(n);
		return (float) (n * 10 / Math.pow(10, decimalCount + 1));
	}

	private static final String str_09_az_AZ = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	private static final char[] arr_09_az_AZ = str_09_az_AZ.toCharArray();

	public static final String intModel_10toD(String N, int d) {
		BigInteger bi = new BigInteger(N);
		BigInteger bi1 = new BigInteger("1");
		BigInteger bid = new BigInteger("" + d);
		int s;
		String e = "";
		while (bi.compareTo(bi1) > 0) {
			s = (bi.mod(bid)).intValue();
			char c = arr_09_az_AZ[s];
			e = c + e;
			bi = bi.divide(bid);
		}
		return e;
	}

	public static final long intModel_Dto10(String str, int d) {
		long num = 0;
		for (int i = 0; i < str.length(); i++) {
			int code = str_09_az_AZ.indexOf(str.charAt(i));
			num += code * Math.pow(d, str.length() - 1 - i);
		}
		return num;
	}

	public static void main(String[] args) {
		System.out.println(intModel_10toD("3468450800375573",62));
		System.out.println(Math.pow(62, 1));
		System.out.println(intModel_Dto10(intModel_10toD("fSU1kcEfj", 62), 62));
		System.out.println(intModel_10toD("" + intModel_Dto10("a", 62), 62));
	}
}
